package com.dubbo.cp.provider.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


import com.dubbo.cp.entity.UserEntity;

/**
 * 
 * @author 林景锋
 *
 */

@Mapper
public interface UserMapper {
	
    /*
     * 这是基于注解的映射方式，实现对数据的增删改查，将sql语句直接写在注解的括号中
     * 这是一个接口，其不需要类去实现它
     * 下边分别是插入，删除，修改，查询一个记录，查询所有的记录
     * */
	@Select("SELECT * FROM user where 1 = 1")
	public List<UserEntity> getUserList();
	
    @Select("SELECT * FROM user WHERE id = #{id}")
    public UserEntity findUserByUserid(@Param("id")int id);
    
	
    @Select("SELECT * FROM user WHERE username = #{username}")
    public UserEntity findUserByUsername(@Param("username")String username);

    @Insert("insert into user(username,password) values(#{username},#{password})")
    public void insertUserEntity(UserEntity userEntity);
    
    @Insert("insert into user(username,password,idcard,address,number,role) values(#{username},#{password},#{idcard},#{address},#{number},#{role})")
    public void insertUserEntity1(UserEntity userEntity);
    
    @Delete("delete from user where id=#{id}")
    public void deleteById(int id);
    
    @Update("update user set username=#{username},password=#{password},idcard=#{idcard},address=#{address},number=#{number} where id=#{id}")
    public void updateUserEntity(UserEntity userEntity);
    
    @Select("SELECT * FROM user WHERE username = #{username} and password = #{password}")
    public UserEntity getUser(@Param("username")String username,@Param("password")String password);

	@Select("select * from user limit #{arg0},#{arg1} ")
    public List<UserEntity>getUserByPage(int start, int size);//分页查询用户的信息
}
